<template>
	<div class="category-content">
		<div class="main-width">
			<div class="promotions-item" v-for="item in list">
				<router-link tag="div" :to="{name: 'PromotionsDetail', query:{id: item.activityId}}">
					<div class="promotions-item-image">
						<img :src="imgAddress + item.picturePath" @error="error(3)">
					</div>
					<div class="promotions-item-content">
						<div class="promotions-item-title">{{item.title}}</div>
						<div class="promotions-item-time">
							<label>活动开始时间：{{item.startTime}}</label>
						</div>
						<div class="promotions-item-time">
							<label>活动结束时间：{{item.endTime}}</label>
						</div>
						<div class="promotions-item-remark" v-if="item.remark == ''">
							无
						</div>
						<div class="promotions-item-remark" v-else>
							{{item.remark}}
						</div>
						<div class="font-right promotions-update-time">时间：{{item.releaseTime}}</div>
					</div>
				</router-link>
			</div>
			<div class="block">
				<el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :current-page.sync="pageNum" :total="total" :page-size="10"></el-pagination>
			</div>
		</div>
	</div>
</template>
<script>
	import {getSalesPromotionList, imgAddress} from '../config/interface.js'
	import {toast, imageError} from '../util/tool.js'
	import {fetch} from '../config/fetch.js'
	import store from '../store/index.js'

	export default {
		data(){
			return {
				pageNum: 1,
				total: 0,
				userId: store.state.userId,
				list: [],
				imgAddress: imgAddress
			}
		},
		mounted(){
			this.init();
		},
		methods: {
			error(num){
				imageError(num, event);
			},
			init(){
				const data = {
					pageNum: this.pageNum,
					pageSize: 10,
					userId: this.userId
				};
				const url = getSalesPromotionList;

				fetch(url, data)
				.then(res => {
					this.list = res.data.list;
					for(var i = 0; i < this.list.length; i++){
						this.list[i].startTime = this.list[i].startTime.substring(0,19);
						this.list[i].endTime = this.list[i].endTime.substring(0,19);
						this.list[i].releaseTime = this.list[i].releaseTime.substring(0,19);
					}
					this.total = res.data.count;
				})
			},
			handleCurrentChange(val) {
		        this.condition.pageNum = val;
		        this.isSelect = false
		        this.init();
		    }
		}
	}
</script>